package com.huxin.servelt;


import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.*;
import java.io.IOException;

@WebServlet("/user/logout")
public class UserLogoutServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        HttpSession session = req.getSession();
        session.invalidate();
        System.out.println("删除cookie");
        //删除cookie
        Cookie username = new Cookie("username","");
        Cookie password = new Cookie("password","");
        Cookie jizhuwo = new Cookie("jizhuwo","");

        username.setMaxAge(0);
        jizhuwo.setMaxAge(0);
        password.setMaxAge(0);


        resp.addCookie(username);
        resp.addCookie(jizhuwo);
        resp.addCookie(password);

        resp.getWriter().write("1");
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doPost(req, resp);
    }
}
